import { defineStore } from 'pinia'
import { ref } from 'vue'
const router = useRouter()
export const useSiteStore = defineStore(
  storesKey.site,
  () => {
    const siteInfo = ref({
      id: '1',
      domain: ''
    })
    /**
     * 设置站点信息
     *
     * @param info 需要设置的站点信息
     * @param refresh 是否刷新页面，默认为 false
     */
    const setSiteInfo = (info: any, refresh: boolean = false) => {
      siteInfo.value = { ...siteInfo.value, ...info }
      if (!refresh) return
      router.replace({ name: 'SiteConfig', params: { id: info?.id } })
      window.location.reload()
    }
    return {
      siteInfo,
      setSiteInfo
    }
  },
  {
    persist: true
  }
)
